      SUBROUTINE MESAGE(KADDON,KOUNT,MAXKNT,KSTOPIT,KBLANK1,KBLANK2,
     1                  LUPRNT,TEXT)
C
C  THIS ROUTINE IS USED TO WRITE A SINGLE LINE OF TEXT(131 OR FEWER
C  CHARACTERS) ON A SPECIFIED UNIT. THIS ROUTINE INCREMENTS A COUNTER,
C  CHECKS IT AGAINST A MAX COUNTER, PERHAPS WRITES THE TEXT, AND STOPS
C  PROGRAM EXECUTION IF CALLER SAYS TO DO SO WHEN MAX COUNT IS 
C  EXCEEDED.
C
C VARIABLE DIM TYPE I/O  DESCRIPTION
C -------- --- ---- ---  -----------
C
C KADDON    1  I*4   I   FLAG TELLING THIS ROUTINE WHETHER TO INCREMENT
C                        THE VARIABLE KOUNT(DESCRIBED BELOW).
C                        = 0, DO NOT INCREMENT. OTHERWISE, INCREMENT IT.
C
C                        KADDON IS USEFUL IF THE USER WANTS TO CALL 
C                        MESAGE WITH KOUNT AS AN INTEGER CONSTANT, AS
C                        WHEN A ROUTINE DETECTS A FATAL ERROR AND THE
C                        PROGRAMMER DOES NOT WANT TO INITIALIZE A
C                        VARIABLE TO INPUT IN THE KOUNT POSITION.
C
C KOUNT     1  I*4  I/O  THE COUNTER. COMPARED AGAINST MAXKNT.
C
C                        IF KADDON IS NON-ZERO, KOUNT IS INCREMENTED BY 
C                        1 FOR OUTPUT. IN THIS CASE, KOUNT MUST BE A 
C                        VARIABLE IN THE CALLING ROUTINE.
C
C                        IF KADDON IS ZERO, KOUNT IS NOT ALTERED. IN 
C                        THIS CASE IT MAY BE AN INTEGER CONSTANT.
C
C MAXKNT    1  I*4   I   VALUE AGAINST WHICH KOUNT IS COMPARED.
C
C                        IF KOUNT+1 IS LESS THAN OR EQUAL TO MAXKNT,
C                        THE TEXT IS OUTPUT. IF KOUNT+1 EXCEEDS MAXKNT,
C                        NO TEXT IS OUTPUT. 
C
C                        IF MAXKNT=0 OR NEGATIVE, THIS ROUTINE OPERATES
C                        AS THOUGH MAXKNT=1 WERE INPUT.
C
C KSTOPIT   1  I*4   I   FLAG INDICATING WHETHER THE PROGRAM IS TO BE
C                        STOPPED IF KOUNT+1 EXCEEDS MAXKNT.
C                        = 0, NO STOP. OTHERWISE, STOP THE PROGRAM.
C
C KBLANK1   1  I*4   I   NUMBER OF BLANK LINES TO PRECEED THE LINE
C                        OF TEXT. FOR SPACING. 0 THRU 10 ONLY.
C
C KBLANK2   1  I*4   I   NUMBER OF BLANK LINES TO FOLLOW THE LINE 
C                        OF TEXT. FOR SPACING. 0 THRU 10 ONLY.
C
C LUPRNT    1  I*4   I   FORTRAN UNIT NUMBER TO WHICH THE MESSAGE IS
C                        SENT. =0 OR NEGATIVE MEANS NO MESSAGE OUTPUT.
C
C TEXT      -  CH*(*) I  TEXT TO BE OUTPUT. 131 CHARACTER MAX FOR
C                        PRINTER. NO ERROR CHECK.
C
C  SAMPLE CALL:
C      CALL MESAGE(1,NERR,MAXERR,1,3,0,LUPRINT,
C     1       'THIS IS AN EXAMPLE. ')
C
C
C*********************************************************************
C
C CODED BY C PETRUZZO, 11/82.
C  MODIFIED...
C       2/83. CJP. CHANGED MESSAGE GIVEN WITH STOP.
C
C*********************************************************************
C
C
      CHARACTER*(*) TEXT
C
      KTEST=MAXKNT
      IF(KTEST.LE.0) KTEST=1
      KNOW=KOUNT+1
C
      IF(KNOW.LE.KTEST .AND. LUPRNT.GT.0) THEN
        IF(KBLANK1.GT.0 .AND. KBLANK1.LE.10) 
     1              WRITE(LUPRNT,1) (' ',I=1,KBLANK1)
        WRITE(LUPRNT,2) TEXT
        IF(KBLANK2.GT.0 .AND. KBLANK2.LE.10) 
     1              WRITE(LUPRNT,1) (' ',I=1,KBLANK2)
        END IF
C
      IF(KSTOPIT.NE.0) THEN
        IF(KNOW.GE.KTEST) THEN
          IF(LUPRNT.GT.0) THEN
            IF(KNOW.GT.KTEST) WRITE(LUPRNT,2) TEXT
            WRITE(LUPRNT,3) 
            END IF
          STOP ' PROGRAM STOPPED BY THE ''MESAGE'' ROUTINE.'
          END IF
        END IF
C
      IF(KADDON.NE.0) KOUNT=KOUNT+1
C
      RETURN
    1 FORMAT(1X,A)
    2 FORMAT(1X,A)
    3 FORMAT(/,
     1 ' ************************************'//,
     2 ' MAX MESSAGES MET OR EXCEEDED.'/,
     3 ' PROGRAM STOPPED BY ''MESAGE'' ROUTINE.'//,
     4 ' ************************************'/)
      END
